/**
* @brief PDF文档阅读器的单页面显示模块.
*/
#ifndef CPDFCANVAS_H
#define CPDFCANVAS_H

#include <wx/wx.h>
#include <poppler/cpp/poppler-document.h>
#include <poppler/cpp/poppler-image.h>
#include <poppler/cpp/poppler-page.h>
#include <poppler/cpp/poppler-page-renderer.h>
#include <poppler/cpp/poppler-rectangle.h>

class CPdfReader;

class CPdfCanvas
{
public:
    enum en_err_code{
        ERR_CAN_NOT_CREATE_PAGE = -1000,
        ERR_PAGE_NOT_EXIST,
        OK = 0
    };
public:
    CPdfCanvas();
    CPdfCanvas( CPdfReader* reader , poppler::page *page,
               poppler::rotation_enum orient =  poppler::rotate_0,
               double scale = 1.0 , double xres = 92.0 , double yres = 92.0);
    virtual ~CPdfCanvas();

    void Scale( double s = 1.0 );
    double GetScale(){ return m_scale; }
    /**
    * @brief
    */
    int Render( poppler::page *page );
    int Render();

    void SetOrient( poppler::rotation_enum orient );

    wxImage& GetImage(){ return *p_img; }
    bool IsPageOK(){ return p_img != NULL; }
    wxPoint& GetSize(){return m_size; }

    void SetPos( int x , int y ){ m_pos.x = x; m_pos.y = y;}

    int GetX(){ return m_pos.x;}
    int GetY(){ return m_pos.y; }
    int GetW(){ return m_size.x; }
    int GetH(){ return m_size.y; }

    void ClearImage(){ if( p_img != NULL ) delete p_img; p_img = NULL;}
private:
    int do_render( poppler::page *page );
private:
    double      m_scale;                               //缩放比例
    wxPoint     m_size;                                //页面的位置和尺寸
    wxPoint     m_pos;
    poppler::rotation_enum    m_ori;                   //页面显示方向
    poppler::page *p_page;

    double      m_xres;                                //
    double      m_yres;

    wxImage     *p_img;                                 //渲染完成的图片
    en_err_code  m_err;

    CPdfReader  *p_reader;
};

#endif // CPDFCANVAS_H
